home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 39.9 KB | 1,299 lines | [TEXT/MPS ] |
- // PascalString.h
- // Copyright © 1985-96 by Apple Computer, Inc. All rights reserved.
-
-
- #ifndef __PASCALSTRING__
- #define __PASCALSTRING__
-
- // MacApp
-
- #ifndef __MACONDITIONALMACROS__
- #include "MAConditionalMacros.h"
- #endif
-
- // Toolbox
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- // ANSI
-
- #ifndef __STRING__
- #include <string.h>
- #endif
-
- #ifndef __LIMITS__
- #include <Limits.h>
- #endif
-
- // If Length() is defined as a macro in Types.h, undefine it
- // so we can have member functions with the same name
- #ifdef Length
- #undef Length
- #endif
-
- // Forward declaration for all the CCharStr classes.
- class CCharStr;
- class CChar255;
- class CChar63;
- class CChar32;
- class CChar31;
- class CChar27;
- class CChar15;
- class CChar2;
- typedef class CCharStr *CCharStrPtr, **CCharStrHandle;
-
- // Forward declaration for all the CPascalStr classes.
- class CPascalStr;
- class CStr255;
- class CStr63;
- class CStr32;
- class CStr31;
- class CStr27;
- class CStr15;
- class CStr2;
- typedef class CPascalStr *CPascalStrPtr, **CPascalStrHandle;
- // Leave in old style name for anyone that needs it.
- typedef class CPascalStr CString, *CStringPtr, **CStringHandle;
-
- typedef const CStr255& ConstCStr255Param;
- typedef const CStr63& ConstCStr63Param;
- typedef const CStr32& ConstCStr32Param;
- typedef const CStr31& ConstCStr31Param;
- typedef const CStr27& ConstCStr27Param;
- typedef const CStr15& ConstCStr15Param;
- typedef const CStr2& ConstCStr2Param;
-
- // Some constants defining the length of each of the CPascalStr types.
-
- const unsigned char kStr255Len = 255;
- const unsigned char kStr63Len = 63;
- const unsigned char kStr32Len = 32;
- const unsigned char kStr31Len = 31;
- const unsigned char kStr27Len = 27;
- const unsigned char kStr15Len = 15;
- const unsigned char kStr2Len = 2;
- const unsigned char kLengthByte = 1;
-
- //----------------------------------------------------------------------------------------
- // MABlockMove: BlockMoveData() is fastest on PowerPC, memcpy() on 68K
- //----------------------------------------------------------------------------------------
-
- #if qPowerPC
- #define MABlockMove(srcPtr, destPtr, byteCount) \
- ::BlockMoveData(srcPtr, destPtr, Size(byteCount))
- #elif UINT_MAX >= ULONG_MAX
- // size_t is (usually) defined as an unsigned int. If we are compiled with 2-byte ints,
- // it will be smaller than a long. We want to use memcpy because it is faster,
- // but it only takes a size_t for the byte count. So we use memcpy for short
- // moves, and BlockMove for the long ones.
- #define MABlockMove(srcPtr, destPtr, byteCount) \
- ::memcpy(destPtr, srcPtr, size_t(byteCount))
- #else
- void MABlockMove(const void* srcPtr, void* destPtr, long byteCount);
- #endif
-
- //----------------------------------------------------------------------------------------
- // MABlockMoveOverlap: BlockMoveData() is fastest on PowerPC, memmove() on 68K
- //----------------------------------------------------------------------------------------
-
- #if qPowerPC
- #define MABlockMoveOverlap(srcPtr, destPtr, byteCount) \
- ::BlockMoveData(srcPtr, destPtr, Size(byteCount))
- #elif UINT_MAX >= ULONG_MAX
- // size_t is (usually) defined as an unsigned int. If we are compiled with 2-byte ints,
- // it will be smaller than a long. We want to use memcpy because it is faster,
- // but it only takes a size_t for the byte count. So we use memcpy for short
- // moves, and BlockMove for the long ones.
- #define MABlockMoveOverlap(srcPtr, destPtr, byteCount) \
- ::memmove(destPtr, srcPtr, size_t(byteCount));
- #else
- void MABlockMoveOverlap(const void* srcPtr, void* destPtr, long byteCount);
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // CCharStr: simple class to enclose a null terminated c style string.
- //----------------------------------------------------------------------------------------
- class CCharStr
- {
- public:
- //
- // No Constructors provided. We don't want anyone constructing this class
- // directly since it has no storage. Besides, constructors and assignment operators
- // are not inherited anyways.
- //
- void CopyFrom(const unsigned char* str, unsigned char maxLength);
- // From Pascal style string with length byte at beginning
-
- void CopyFrom(const char* str, size_t maxLength);
- // From C style string with null terminator at end
-
- void CopyFrom(const void* str, size_t forLength);
- // From raw memory for a given length
-
- inline size_t Length() const
- { return strlen(((const char*)this)); }
-
- inline Boolean IsEmpty() const
- { return *((const char*)this) == 0; }
-
- // Character selector operator.
-
- inline char& operator[](size_t index)
- { return ((char*)this)[index]; }
-
- inline char operator[](size_t index) const
- { return ((const char*)this)[index]; }
-
- inline operator const char*() const
- { return (const char*)this; }
-
- inline operator char*()
- { return (char*)this; }
- };
-
- //----------------------------------------------------------------------------------------
- // CChar255:
- //----------------------------------------------------------------------------------------
- class CChar255 : public CCharStr
- {
- enum { kMaxLength = kStr255Len };
- char fStr[kMaxLength + 1];
-
- public:
- inline CChar255()
- { *(char*)this = 0; }
-
- inline CChar255(const char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CChar255(const unsigned char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CChar255(const void* str, size_t maxLength)
- { CopyFrom(str, maxLength); }
-
- inline CChar255(const CPascalStr& str)
- { CopyFrom((const unsigned char*)&str, kMaxLength); }
-
- inline CChar255(const CStr255& str)
- { CopyFrom((const unsigned char*)&str, kMaxLength); }
- };
-
- //----------------------------------------------------------------------------------------
- // CChar63:
- //----------------------------------------------------------------------------------------
- class CChar63 : public CCharStr
- {
- enum { kMaxLength = kStr63Len };
- char fStr[kMaxLength + 1];
-
- public:
- inline CChar63()
- { *(char*)this = 0; }
-
- inline CChar63(const char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CChar63(const unsigned char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CChar63(const void* str, size_t maxLength)
- { CopyFrom(str, maxLength); }
-
- inline CChar63(const CPascalStr& str)
- { CopyFrom((const unsigned char*)&str, kMaxLength); }
-
- inline CChar63(const CStr63& str)
- { CopyFrom((const unsigned char*)&str, kMaxLength); }
- };
-
- //----------------------------------------------------------------------------------------
- // CChar32:
- //----------------------------------------------------------------------------------------
- class CChar32 : public CCharStr
- {
- enum { kMaxLength = kStr32Len };
- char fStr[kMaxLength + 1];
-
- public:
- inline CChar32()
- { *(char*)this = 0; }
-
- inline CChar32(const char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CChar32(const unsigned char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CChar32(const void* str, size_t maxLength)
- { CopyFrom(str, maxLength); }
-
- inline CChar32(const CPascalStr& str)
- { CopyFrom((const unsigned char*)&str, kMaxLength); }
-
- inline CChar32(const CStr32& str)
- { CopyFrom((const unsigned char*)&str, kMaxLength); }
- };
-
- //----------------------------------------------------------------------------------------
- // CChar31:
- //----------------------------------------------------------------------------------------
- class CChar31 : public CCharStr
- {
- enum { kMaxLength = kStr31Len };
- char fStr[kMaxLength + 1];
-
- public:
- inline CChar31()
- { *(char*)this = 0; }
-
- inline CChar31(const char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CChar31(const unsigned char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CChar31(const void* str, size_t maxLength)
- { CopyFrom(str, maxLength); }
-
- inline CChar31(const CPascalStr& str)
- { CopyFrom((const unsigned char*)&str, kMaxLength); }
-
- inline CChar31(const CStr31& str)
- { CopyFrom((const unsigned char*)&str, kMaxLength); }
- };
-
-
- //----------------------------------------------------------------------------------------
- // CChar27:
- //----------------------------------------------------------------------------------------
- class CChar27 : public CCharStr
- {
- enum { kMaxLength = kStr27Len };
- char fStr[kMaxLength + 1];
-
- public:
- inline CChar27()
- { *(char*)this = 0; }
-
- inline CChar27(const char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CChar27(const unsigned char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CChar27(const void* str, size_t maxLength)
- { CopyFrom(str, maxLength); }
-
- inline CChar27(const CPascalStr& str)
- { CopyFrom((const unsigned char*)&str, kMaxLength); }
-
- inline CChar27(const CStr27& str)
- { CopyFrom((const unsigned char*)&str, kMaxLength); }
- };
-
-
- //----------------------------------------------------------------------------------------
- // CChar15:
- //----------------------------------------------------------------------------------------
- class CChar15 : public CCharStr
- {
- enum { kMaxLength = kStr15Len };
- char fStr[kMaxLength + 1];
-
- public:
- inline CChar15()
- { *(char*)this = 0; }
-
- inline CChar15(const char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CChar15(const unsigned char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CChar15(const void* str, size_t maxLength)
- { CopyFrom(str, maxLength); }
-
- inline CChar15(const CPascalStr& str)
- { CopyFrom((const unsigned char*)&str, kMaxLength); }
-
- inline CChar15(const CStr15& str)
- { CopyFrom((const unsigned char*)&str, kMaxLength); }
- };
-
-
- //----------------------------------------------------------------------------------------
- // CChar2:
- //----------------------------------------------------------------------------------------
- class CChar2 : public CCharStr
- {
- enum { kMaxLength = kStr2Len };
- char fStr[kMaxLength + 1];
-
- public:
- inline CChar2()
- { *(char*)this = 0; }
-
- inline CChar2(const char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CChar2(const unsigned char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CChar2(const void* str, size_t maxLength)
- { CopyFrom(str, maxLength); }
-
- inline CChar2(const CPascalStr& str)
- { CopyFrom((const unsigned char*)&str, kMaxLength); }
-
- inline CChar2(const CStr2& str)
- { CopyFrom((const unsigned char*)&str, kMaxLength); }
- };
-
-
- //----------------------------------------------------------------------------------------
- // CPascalStr: Superclass of all Pascal string compatible string classes.
- //----------------------------------------------------------------------------------------
- class CPascalStr
- {
- public:
- //
- // No Constructors provided. We don't want anyone constructing this class
- // directly since it has no storage. Besides, constructors and assignment operators
- // are not inherited anyways.
- //
- void CopyFrom(const unsigned char* str, unsigned char maxLength);
- // From Pascal style string with length byte at beginning
-
- void CopyFrom(const char* str, unsigned char maxLength);
- // From C style string with null terminator at end
-
- void CopyFrom(const void* str, unsigned char forLength);
- // From raw memory for a given length
-
- void CopyFrom(const unsigned char* str);
- // From Pascal style string with length byte at beginning
- // Copies up to kStr255Len bytes, be careful
-
- void CopyFrom(const char* str);
- // From C style string with null terminator at end
- // Copies up to kStr255Len bytes, be careful
-
- #if qPowerPC || qNeedsMC68020
- inline void CopyFrom(unsigned long id)
- { *((unsigned char*)this) = sizeof(id); *(unsigned long*)&((unsigned char*)this)[1] = id; }
- #else
- void CopyFrom(unsigned long id);
- #endif
- // From a long value directly into the string
-
- #if qPowerPC || qNeedsMC68020
- inline void CopyFrom(unsigned short num)
- { *((unsigned char*)this) = sizeof(num); *(unsigned short*)&((unsigned char*)this)[1] = num; }
- #else
- void CopyFrom(unsigned short num);
- #endif
- // From a short value directly into the string
-
- inline void CopyFrom(unsigned char ch)
- { *((unsigned char*)this) = sizeof(ch); ((unsigned char*)this)[1] = ch; }
- // From a short value into the string
-
- inline void CopyFrom(const CPascalStr& str, unsigned char maxLength)
- { CopyFrom((const unsigned char*)&str, maxLength); }
- // From CPascalStr (Pascal) style string with length byte at beginning
-
- inline void CopyFrom(const CPascalStr& str)
- { CopyFrom((const unsigned char*)&str); }
- // From CPascalStr (Pascal) style string with length byte at beginning
- // Copies up to kStr255Len bytes, be careful
-
- void CopyTo(unsigned char* str) const;
- // Copies this string TO str with a length byte
-
- void CopyTo(char* str) const;
- // Copies this string TO str with a null termination
-
- void CopyTo(void* str) const;
- // Copies this string TO str without a null termination
-
- unsigned char GetMaxLength(unsigned char pos, unsigned char length) const;
- // returns the maximum length to copy starting from pos
- // for length characters OR the length of the string whichever comes first.
-
- //
- // Character selection operator.
- //
- inline unsigned char& operator[](int pos)
- { return ((unsigned char*)this)[pos]; }
-
- inline const unsigned char& operator[](int pos) const
- { return ((const unsigned char*)this)[pos]; }
-
- //
- // Basic length method, inherited by all derived classes. Returns a reference
- //
- inline unsigned char& Length()
- { return *((unsigned char*)this); }
-
- inline const unsigned char& Length() const
- { return *((const unsigned char*)this); }
-
- inline Boolean IsEmpty() const
- { return !*(const unsigned char*)this; }
-
- inline void Empty()
- { *(unsigned char*)this = 0; }
-
- // Returns a copy of the string on the stack. (as a null terminated c style string)
- inline operator const char*() const
- { return CChar255(*this); }
-
- // Used to create a toolbox type Str255, etc. from our CPascalStr. This is simply a type
- // coercion! Both CPascalStr and Str255, etc. are expected to be pascal-style strings.
- inline operator unsigned char*()
- { return (unsigned char *) this; }
-
- inline operator const unsigned char*() const
- { return (const unsigned char *) this; }
-
- //------------------------------------------------------------------------------------
-
- // Return an ID represented as a CPascalStr to the actual ID (an unsigned long).
-
- #if qPowerPC || qNeedsMC68020
- inline unsigned long ToULong() const
- { return *((unsigned long *) &(*this)[1]); } // odd pointers OK
- #else
- unsigned long ToULong() const;
- #endif
-
- #if qPowerPC || qNeedsMC68020
- inline unsigned short ToUShort() const
- { return *((unsigned short *) &(*this)[1]); } // odd pointers OK
- #else
- unsigned short ToUShort() const;
- #endif
-
- // Relational operators that are inherited by all the derived CPascalStr types. Five of
- // each so that literal C Strings and characters can be conveniently used for one of the
- // operators as well as two of the derived classes as operators.
- static short CPascalStrCompare(const CPascalStr& s1, const CPascalStr& s2);
- static short CPascalStrCompare(const CPascalStr& s1, const char* s2);
- static short CPascalStrCompare(const CPascalStr& s1, unsigned char ch);
- static short CPascalStrCompare(const char* s1, const CPascalStr& s2);
- static short CPascalStrCompare(unsigned char ch, const CPascalStr& s2);
-
- friend Boolean operator==(const CPascalStr& s1, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) == 0; }
- friend Boolean operator==(const CPascalStr& s1, const char* s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) == 0; }
- friend Boolean operator==(const CPascalStr& s1, unsigned char ch)
- { return CPascalStr::CPascalStrCompare(s1, ch) == 0; }
- friend Boolean operator==(const char* s1, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) == 0; }
- friend Boolean operator==(unsigned char ch, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(ch, s2) == 0; }
-
- friend Boolean operator!=(const CPascalStr& s1, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) != 0; }
- friend Boolean operator!=(const CPascalStr& s1, const char* s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) != 0; }
- friend Boolean operator!=(const CPascalStr& s1, unsigned char ch)
- { return CPascalStr::CPascalStrCompare(s1, ch) != 0; }
- friend Boolean operator!=(const char* s1, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) != 0; }
- friend Boolean operator!=(unsigned char ch, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(ch, s2) != 0; }
-
- friend Boolean operator>(const CPascalStr& s1, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) > 0; }
- friend Boolean operator>(const CPascalStr& s1, const char* s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) > 0; }
- friend Boolean operator>(const CPascalStr& s1, unsigned char ch)
- { return CPascalStr::CPascalStrCompare(s1, ch) > 0; }
- friend Boolean operator>(const char* s1, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) > 0; }
- friend Boolean operator>(unsigned char ch, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(ch, s2) > 0; }
-
- friend Boolean operator<(const CPascalStr& s1, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) < 0; }
- friend Boolean operator<(const CPascalStr& s1, const char* s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) < 0; }
- friend Boolean operator<(const CPascalStr& s1, unsigned char ch)
- { return CPascalStr::CPascalStrCompare(s1, ch) < 0; }
- friend Boolean operator<(const char* s1, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) < 0; }
- friend Boolean operator<(unsigned char ch, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(ch, s2) < 0; }
-
- friend Boolean operator>=(const CPascalStr& s1, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) >= 0; }
- friend Boolean operator>=(const CPascalStr& s1, const char* s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) >= 0; }
- friend Boolean operator>=(const CPascalStr& s1, unsigned char ch)
- { return CPascalStr::CPascalStrCompare(s1, ch) >= 0; }
- friend Boolean operator>=(const char* s1, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) >= 0; }
- friend Boolean operator>=(unsigned char ch, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(ch, s2) >= 0; }
-
- friend Boolean operator<=(const CPascalStr& s1, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) <= 0; }
- friend Boolean operator<=(const CPascalStr& s1, const char* s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) <= 0; }
- friend Boolean operator<=(const CPascalStr& s1, unsigned char ch)
- { return CPascalStr::CPascalStrCompare(s1, ch) <= 0; }
- friend Boolean operator<=(const char* s1, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(s1, s2) <= 0; }
- friend Boolean operator<=(unsigned char ch, const CPascalStr& s2)
- { return CPascalStr::CPascalStrCompare(ch, s2) <= 0; }
-
- // Concatenation operator that are inherited by all the derived CPascalStr types. Three
- // of each so that literal C Strings can be conveniently used for one of the operators
- // as well as using any two classes derived from CPascalStr.
- friend CStr255 operator+(const CPascalStr& s1, const CPascalStr& s2);
- friend CStr255 operator+(const CPascalStr& s1, const char* s2);
- friend CStr255 operator+(const CPascalStr& s1, unsigned char ch);
- friend CStr255 operator+(const char* s1, const CPascalStr& s2);
- friend CStr255 operator+(unsigned char ch, const CPascalStr& s2);
-
- // Methods that mimic the Pascal builtin CPascalStr functions for Pos, Insert and Delete.
- // Note that insert and copy is implemented in the derived classes.
- unsigned char Pos(const char* subStr, unsigned char startPos = 1);
- unsigned char Pos(const CPascalStr& subStr, unsigned char startPos = 1);
- void Delete(unsigned char pos, unsigned char length);
-
- void Insert(const char* insStr, unsigned char insStrLength, unsigned char pos, unsigned char maxLength);
- void Insert(const char* insStr, unsigned char pos, unsigned char maxLength);
- void Insert(const char* insStr, unsigned char pos);
- void Insert(const CPascalStr& insStr, unsigned char pos, unsigned char maxLength);
- void Insert(const CPascalStr& insStr, unsigned char pos);
-
-
- //----------------------------------------------------------------------------------------
- // static member functions
- //----------------------------------------------------------------------------------------
- static Handle SetItl2Handle(Handle itsItl2Handle);
-
- //----------------------------------------------------------------------------------------
- // static data members
- //----------------------------------------------------------------------------------------
- static Handle fgItl2Handle; // Handle to the international rsrc to be used
- // in string compares. Normally NULL, MacApp depends on
- // The system value for proper operation of it's internal
- // Strings, However you may replace and restore this
- // during certain of your own operations.
- };
-
-
- //----------------------------------------------------------------------------------------
- // CStr255:
- //----------------------------------------------------------------------------------------
- class CStr255 : public CPascalStr
- {
- public:
- enum { kMaxLength = kStr255Len };
- Str255 fStr;
-
- public:
- inline CStr255()
- { *(unsigned char*)this = 0; }
-
- inline CStr255(const CPascalStr& str)
- { CopyFrom(str); }
- // Generic string constructor
-
- inline CStr255(const CStr255& str)
- { CopyFrom(str); }
- // copy constructor
-
- //
- // Don't have any optimized constructors for string smaller than me.
- // Because all other strings are smaller than me, so we don't need any.
- //
-
- inline CStr255(const unsigned char* str)
- { CopyFrom(str); }
-
- inline CStr255(const char* str)
- { CopyFrom(str); }
-
- inline CStr255(const char* str, unsigned char maxLength)
- { CopyFrom(str, maxLength); }
-
- inline CStr255(const void* str, unsigned char forLength)
- { CopyFrom(str, forLength); }
-
- inline CStr255(unsigned long id)
- { CopyFrom(id); }
-
- inline CStr255(unsigned short num)
- { CopyFrom(num); }
-
- inline CStr255(unsigned char ch)
- { CopyFrom(ch); }
-
- // Returns a copy of the string on the stack. (as a null terminated c style string)
- inline operator const char*() const
- { return CChar255(*this); }
-
- // Copy and Insert roughly equivalent to the Pascal Insert and Copy functions.
-
- inline CStr255& Copy(unsigned char pos, unsigned char length) const
- { return CStr255((const char*)&(*this)[pos], GetMaxLength(pos, length)); }
-
- inline void Insert(const CPascalStr& str, unsigned char pos)
- { CPascalStr::Insert(str, pos); }
-
- inline void Insert(const char* str, unsigned char pos)
- { CPascalStr::Insert(str, pos); }
-
- // Concatenation operator
-
- inline CStr255& operator +=(const CPascalStr& str)
- { Insert(str, Length() + 1); return *this; }
-
- inline CStr255& operator +=(const char* str)
- { Insert(str, Length() + 1); return *this; }
-
- inline CStr255& operator +=(unsigned char ch)
- { CPascalStr::Insert((const char*)&ch, 1, Length() + 1, kMaxLength); return *this; }
-
- // Assignment operators
- inline CStr255& operator=(const CStr255& str)
- { CopyFrom(str); return *this; }
-
- inline CStr255& operator=(const CPascalStr& str)
- { CopyFrom(str); return *this; }
-
- inline CStr255& operator=(const unsigned char* str)
- { CopyFrom(str); return *this; }
-
- inline CStr255& operator=(const char* str)
- { CopyFrom(str); return *this; }
-
- inline CStr255& operator=(unsigned char ch)
- { CopyFrom(ch); return *this; }
- };
-
-
- //----------------------------------------------------------------------------------------
- // CStr63:
- //----------------------------------------------------------------------------------------
- class CStr63 : public CPascalStr
- {
- public:
- enum { kMaxLength = kStr63Len };
- Str63 fStr;
-
- public:
- // Constructors
-
- inline CStr63()
- { *(unsigned char*)this = 0; }
-
- inline CStr63(const CPascalStr& str)
- { CopyFrom(str, kMaxLength); }
- // Generic string constructor
-
- inline CStr63(const CStr63& str)
- { CopyFrom(str); }
- // copy constructor
-
- inline CStr63(const CStr32& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr63(const CStr31& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr63(const CStr27& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr63(const CStr15& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr63(const CStr2& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr63(const unsigned char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CStr63(const char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CStr63(const char* str, unsigned char maxLength)
- { CopyFrom(str, maxLength); }
-
- inline CStr63(const void* str, unsigned char forLength)
- { CopyFrom(str, forLength); }
-
- inline CStr63(unsigned long id)
- { CopyFrom(id); }
-
- inline CStr63(unsigned short num)
- { CopyFrom(num); }
-
- inline CStr63(unsigned char ch)
- { CopyFrom(ch); }
-
- // Returns a copy of the string on the stack. (as a null terminated c style string)
- inline operator const char*() const
- { return CChar63(*this); }
-
- // Copy and Insert roughly equivalent to the Pascal Insert and Copy functions.
-
- inline CStr63 Copy(unsigned char pos, unsigned char length) const
- { return CStr63((const char*)&(*this)[pos], GetMaxLength(pos, length)); }
-
- inline void Insert(const CPascalStr& str, unsigned char pos)
- { CPascalStr::Insert(str, pos, kMaxLength); }
-
- inline void Insert(const char* str, unsigned char pos)
- { CPascalStr::Insert(str, pos, kMaxLength); }
-
- // Concatenation operator
-
- inline CStr63& operator +=(const CPascalStr& str)
- { Insert(str, Length() + 1); return *this; }
-
- inline CStr63& operator +=(const char* str)
- { Insert(str, Length() + 1); return *this; }
-
- inline CStr63& operator +=(unsigned char ch)
- { CPascalStr::Insert((char*)&ch, 1, Length() + 1, kMaxLength); return *this; }
-
- // Assignment operators
-
- inline CStr63& operator=(const CStr63& str)
- { CopyFrom(str); return *this; }
-
- inline CStr63& operator=(const CPascalStr& str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr63& operator=(const unsigned char* str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr63& operator=(const char* str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr63& operator=(unsigned char ch)
- { CopyFrom(ch); return *this; }
- };
-
-
- //----------------------------------------------------------------------------------------
- // CStr32:
- //----------------------------------------------------------------------------------------
- class CStr32 : public CPascalStr
- {
- public:
- enum { kMaxLength = kStr32Len };
- Str32 fStr;
-
- public:
- // Constructors
-
- inline CStr32()
- { *(unsigned char*)this = 0; }
-
- inline CStr32(const CPascalStr& str)
- { CopyFrom(str, kMaxLength); }
- // Generic string constructor
-
- inline CStr32(const CStr32& str)
- { CopyFrom(str); }
- // copy constructor
-
- inline CStr32(const CStr31& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr32(const CStr27& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr32(const CStr15& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr32(const CStr2& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr32(const unsigned char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CStr32(const char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CStr32(const char* str, unsigned char maxLength)
- { CopyFrom(str, maxLength); }
-
- inline CStr32(const void* str, unsigned char forLength)
- { CopyFrom(str, forLength); }
-
- inline CStr32(unsigned long id)
- { CopyFrom(id); }
-
- inline CStr32(unsigned short num)
- { CopyFrom(num); }
-
- inline CStr32(unsigned char ch)
- { CopyFrom(ch); }
-
- // Returns a copy of the string on the stack. (as a null terminated c style string)
- inline operator const char*() const
- { return CChar32(*this); }
-
- // Copy and Insert roughly equivalent to the Pascal Insert and Copy functions.
-
- inline CStr32 Copy(unsigned char pos, unsigned char length) const
- { return CStr32((const char*)&(*this)[pos], GetMaxLength(pos, length)); }
-
- inline void Insert(const CPascalStr& str, unsigned char pos)
- { CPascalStr::Insert(str, pos, kMaxLength); }
-
- inline void Insert(const char* str, unsigned char pos)
- { CPascalStr::Insert(str, pos, kMaxLength); }
-
- // Concatenation operator
-
- inline CStr32& operator +=(const CPascalStr& str)
- { Insert(str, Length() + 1); return *this; }
-
- inline CStr32& operator +=(const char* str)
- { Insert(str, Length() + 1); return *this; }
-
- inline CStr32& operator +=(unsigned char ch)
- { CPascalStr::Insert((char*)&ch, 1, Length() + 1, kMaxLength); return *this; }
-
- // Assignment operators
-
- inline CStr32& operator=(const CStr32& str)
- { CopyFrom(str); return *this; }
-
- inline CStr32& operator=(const CPascalStr& str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr32& operator=(const unsigned char* str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr32& operator=(const char* str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr32& operator=(unsigned char ch)
- { CopyFrom(ch); return *this; }
- };
-
-
- //----------------------------------------------------------------------------------------
- // CStr31:
- //----------------------------------------------------------------------------------------
- class CStr31 : public CPascalStr
- {
- public:
- enum { kMaxLength = kStr31Len };
- Str31 fStr;
-
- public:
- // Constructors
-
- inline CStr31()
- { *(unsigned char*)this = 0; }
-
- inline CStr31(const CPascalStr& str)
- { CopyFrom(str, kMaxLength); }
- // Generic string constructor
-
- inline CStr31(const CStr31& str)
- { CopyFrom(str); }
- // copy constructor
-
- inline CStr31(const CStr27& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr31(const CStr15& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr31(const CStr2& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr31(const unsigned char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CStr31(const char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CStr31(const char* str, unsigned char maxLength)
- { CopyFrom(str, maxLength); }
-
- inline CStr31(const void* str, unsigned char forLength)
- { CopyFrom(str, forLength); }
-
- inline CStr31(unsigned long id)
- { CopyFrom(id); }
-
- inline CStr31(unsigned short num)
- { CopyFrom(num); }
-
- inline CStr31(unsigned char ch)
- { CopyFrom(ch); }
-
- // Returns a copy of the string on the stack. (as a null terminated c style string)
- inline operator const char*() const
- { return CChar31(*this); }
-
- // Copy and Insert roughly equivalent to the Pascal Insert and Copy functions.
-
- inline CStr31 Copy(unsigned char pos, unsigned char length) const
- { return CStr31((const char*)&(*this)[pos], GetMaxLength(pos, length)); }
-
- inline void Insert(const CPascalStr& str, unsigned char pos)
- { CPascalStr::Insert(str, pos, kMaxLength); }
-
- inline void Insert(const char* str, unsigned char pos)
- { CPascalStr::Insert(str, pos, kMaxLength); }
-
- // Concatenation operator
-
- inline CStr31& operator +=(const CPascalStr& str)
- { Insert(str, Length() + 1); return *this; }
-
- inline CStr31& operator +=(const char* str)
- { Insert(str, Length() + 1); return *this; }
-
- inline CStr31& operator +=(unsigned char ch)
- { CPascalStr::Insert((char*)&ch, 1, Length() + 1, kMaxLength); return *this; }
-
- // Assignment operators
-
- inline CStr31& operator=(const CStr31& str)
- { CopyFrom(str); return *this; }
-
- inline CStr31& operator=(const CPascalStr& str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr31& operator=(const unsigned char* str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr31& operator=(const char* str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr31& operator=(unsigned char ch)
- { CopyFrom(ch); return *this; }
- };
-
-
- //----------------------------------------------------------------------------------------
- // CStr27:
- //----------------------------------------------------------------------------------------
- class CStr27 : public CPascalStr
- {
- public:
- enum { kMaxLength = kStr27Len };
- Str27 fStr;
-
- public:
- // Constructors
-
- inline CStr27()
- { *(unsigned char*)this = 0; }
-
- inline CStr27(const CPascalStr& str)
- { CopyFrom(str, kMaxLength); }
- // Generic string constructor
-
- inline CStr27(const CStr27& str)
- { CopyFrom(str); }
- // copy constructor
-
- inline CStr27(const CStr15& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr27(const CStr2& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr27(const unsigned char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CStr27(const char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CStr27(const char* str, unsigned char maxLength)
- { CopyFrom(str, maxLength); }
-
- inline CStr27(const void* str, unsigned char forLength)
- { CopyFrom(str, forLength); }
-
- inline CStr27(unsigned long id)
- { CopyFrom(id); }
-
- inline CStr27(unsigned short num)
- { CopyFrom(num); }
-
- inline CStr27(unsigned char ch)
- { CopyFrom(ch); }
-
- // Returns a copy of the string on the stack. (as a null terminated c style string)
- inline operator const char*() const
- { return CChar27(*this); }
-
- // Copy and Insert roughly equivalent to the Pascal Insert and Copy functions.
-
- inline CStr27 Copy(unsigned char pos, unsigned char length) const
- { return CStr27((const char*)&(*this)[pos], GetMaxLength(pos, length)); }
-
- inline void Insert(const CPascalStr& str, unsigned char pos)
- { CPascalStr::Insert(str, pos, kMaxLength); }
-
- inline void Insert(const char* str, unsigned char pos)
- { CPascalStr::Insert(str, pos, kMaxLength); }
-
- // Concatenation operator
-
- inline CStr27& operator +=(const CPascalStr& str)
- { Insert(str, Length() + 1); return *this; }
-
- inline CStr27& operator +=(const char* str)
- { Insert(str, Length() + 1); return *this; }
-
- inline CStr27& operator +=(unsigned char ch)
- { CPascalStr::Insert((char*)&ch, 1, Length() + 1, kMaxLength); return *this; }
-
- // Assignment operators
-
- inline CStr27& operator=(const CStr27& str)
- { CopyFrom(str); return *this; }
-
- inline CStr27& operator=(const CPascalStr& str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr27& operator=(const unsigned char* str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr27& operator=(const char* str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr27& operator=(unsigned char ch)
- { CopyFrom(ch); return *this; }
- };
-
-
- //----------------------------------------------------------------------------------------
- // CStr15:
- //----------------------------------------------------------------------------------------
- class CStr15 : public CPascalStr
- {
- public:
- enum { kMaxLength = kStr15Len };
- Str15 fStr;
-
- public:
- // Constructors
-
- inline CStr15()
- { *(unsigned char*)this = 0; }
-
- inline CStr15(const CPascalStr& str)
- { CopyFrom(str, kMaxLength); }
- // Generic string constructor
-
- inline CStr15(const CStr15& str)
- { CopyFrom(str); }
- // copy constructor
-
- inline CStr15(const CStr2& str)
- { CopyFrom((const unsigned char*)&str); }
- // Optimized constructor for string smaller than me. You don't have to have this though.
-
- inline CStr15(const unsigned char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CStr15(const char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CStr15(const char* str, unsigned char maxLength)
- { CopyFrom(str, maxLength); }
-
- inline CStr15(const void* str, unsigned char forLength)
- { CopyFrom(str, forLength); }
-
- inline CStr15(unsigned long id)
- { CopyFrom(id); }
-
- inline CStr15(unsigned short num)
- { CopyFrom(num); }
-
- inline CStr15(unsigned char ch)
- { CopyFrom(ch); }
-
- // Returns a copy of the string on the stack. (as a null terminated c style string)
- inline operator const char*() const
- { return CChar15(*this); }
-
- // Copy and Insert roughly equivalent to the Pascal Insert and Copy functions.
-
- inline CStr15 Copy(unsigned char pos, unsigned char length) const
- { return CStr15((const char*)&(*this)[pos], GetMaxLength(pos, length)); }
-
- inline void Insert(const CPascalStr& str, unsigned char pos)
- { CPascalStr::Insert(str, pos, kMaxLength); }
-
- inline void Insert(const char* str, unsigned char pos)
- { CPascalStr::Insert(str, pos, kMaxLength); }
-
- // Concatenation operator
-
- inline CStr15& operator +=(const CPascalStr& str)
- { Insert(str, Length() + 1); return *this; }
-
- inline CStr15& operator +=(const char* str)
- { Insert(str, Length() + 1); return *this; }
-
- inline CStr15& operator +=(unsigned char ch)
- { CPascalStr::Insert((char*)&ch, 1, Length() + 1, kMaxLength); return *this; }
-
- // Assignment operators
-
- inline CStr15& operator=(const CStr15& str)
- { CopyFrom(str); return *this; }
-
- inline CStr15& operator=(const CPascalStr& str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr15& operator=(const unsigned char* str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr15& operator=(const char* str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr15& operator=(unsigned char ch)
- { CopyFrom(ch); return *this; }
- };
-
-
- //----------------------------------------------------------------------------------------
- // CStr2:
- //----------------------------------------------------------------------------------------
- class CStr2 : public CPascalStr
- {
- public:
- enum { kMaxLength = kStr2Len };
- unsigned char fStr[kStr2Len + kLengthByte]; // Str2
-
- public:
- // Constructors
-
- inline CStr2()
- { *(unsigned char*)this = 0; }
-
- inline CStr2(const CPascalStr& str)
- { CopyFrom(str, kMaxLength); }
- // Generic string constructor
-
- inline CStr2(const CStr2& str)
- { CopyFrom(str); }
- // copy constructor
-
- //
- // Don't have any optimized constructors for string smaller than me.
- // Because we haven't defined any yet. Even If you do add more CPascalStr subclasses
- // I will still work correctly, though.
- //
-
- inline CStr2(const unsigned char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CStr2(const char* str)
- { CopyFrom(str, kMaxLength); }
-
- inline CStr2(const char* str, unsigned char maxLength)
- { CopyFrom(str, maxLength); }
-
- inline CStr2(const void* str, unsigned char forLength)
- { CopyFrom(str, forLength); }
-
- // CStr2 certainly isn't big enough for this!
- // CStr2(unsigned long id)
- // { CopyFrom(id); }
-
- inline CStr2(unsigned short num)
- { CopyFrom(num); }
-
- inline CStr2(unsigned char ch)
- { CopyFrom(ch); }
-
- // Returns a copy of the string on the stack. (as a null terminated c style string)
- inline operator const char*() const
- { return CChar2(*this); }
-
- // Copy and Insert roughly equivalent to the Pascal Insert and Copy functions.
-
- inline CStr2 Copy(unsigned char pos, unsigned char length) const
- { return CStr2((const char*)&(*this)[pos], GetMaxLength(pos, length)); }
-
- inline void Insert(const CPascalStr& str, unsigned char pos)
- { CPascalStr::Insert(str, pos, kMaxLength); }
-
- inline void Insert(const char* str, unsigned char pos)
- { CPascalStr::Insert(str, pos, kMaxLength); }
-
- // Concatenation operator
-
- inline CStr2& operator +=(const CPascalStr& str)
- { Insert(str, Length() + 1); return *this; }
-
- inline CStr2& operator +=(const char* str)
- { Insert(str, Length() + 1); return *this; }
-
- inline CStr2& operator +=(char ch)
- { CPascalStr::Insert(&ch, 1, Length() + 1, kMaxLength); return *this; }
-
- // Assignment operators
-
- inline CStr2& operator=(const CStr2& str)
- { CopyFrom(str); return *this; }
-
- inline CStr2& operator=(const CPascalStr& str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr2& operator=(const unsigned char* str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr2& operator=(const char* str)
- { CopyFrom(str, kMaxLength); return *this; }
-
- inline CStr2& operator=(unsigned char ch)
- { CopyFrom(ch); return *this; }
- };
-
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- #endif
-